package com.huabo.sql.type;

import com.huabo.sql.record.JSONB;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by Jackie Liu on 2017/10/3.
 */
public class JSONBTypeHandler extends BaseTypeHandler<JSONB> {

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, JSONB parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.toString());
    }

    @Override
    public JSONB getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String value = rs.getString(columnName);
        return value == null ? null : new JSONB(value);
    }

    @Override
    public JSONB getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String value = rs.getString(columnIndex);
        return value == null ? null : new JSONB(value);
    }

    @Override
    public JSONB getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String value = cs.getString(columnIndex);
        return value == null ? null : new JSONB(value);
    }
}
